package com.xiaotu.code.dao.quene;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaotu.code.dao.SimpleHibernateDao;
import com.xiaotu.code.model.quene.SettingMqQuene;

/**
 * 队列配置DAO.
 * 
 * @author chenxiangrong
 * 
 */
@Repository(value="settingMqQueneDao")
public class SettingMqQueneDao extends SimpleHibernateDao<SettingMqQuene, Long> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2640855538335964181L;

	/**
	 * 查询开启的数据列表.
	 * 
	 * @return
	 */
	public List<SettingMqQuene> getEnabledList() {

		return super.find("from SettingMqQuene where enabled = true ");
	}

	/**
	 * 获取指定节点需要侦听的队列列表.
	 * 
	 * @return
	 */
	public List<SettingMqQuene> getLitenerList(int nodeId) {

		return super.find("from SettingMqQuene where enabled = true and ','|| listenNodes ||',' like ? ", "%," + nodeId
				+ ",%");
	}

	/**
	 * 获取指定节点需要发送的消息体接受者.
	 * 
	 * @param queneName
	 * @param nodeId
	 * @return
	 */
	public SettingMqQuene getLitenerByQueneName(String queneName, int nodeId) {

		return super.findUnique(
				"from SettingMqQuene where enabled = true and  name = ? and ','|| sendNodes|| ',' like ? ", queneName,
				"%," + nodeId + ",%");
	}
}
